package com.qcby.hengxiang.learn.controller;

import com.qcby.hengxiang.learn.entity.User;
import com.qcby.hengxiang.learn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("learn")
public class LearnController {
    @Autowired
    private UserService userService;

    @RequestMapping("first")
    @ResponseBody
    public String first(HttpServletRequest request, HttpServletResponse response) {
        String user = request.getParameter("user");
        System.out.println(request.getParameter("password"));
        System.out.println(user);
        return "我是一个好人";
    }
    @RequestMapping("first1")
    @ResponseBody
    public String first1(String user,String password) {

        System.out.println(password);
        System.out.println(user);
        return "我是一个好人1";
    }
    @RequestMapping("first2")
    @ResponseBody
    public String first2(@RequestParam("user") String user1, @RequestParam("password") String password1) {
        User user = new User();
//        user.setUser(user1);
//        user.setPassword(password1);
        System.out.println(password1);
        System.out.println(user1);
        return "我是一个好人1";
    }
    @RequestMapping("first3")
    @ResponseBody
    public List<User>  first3() {
        List<User> users = userService.getUsers();
        return users;
    }
    @RequestMapping("first4/{id}")
    @ResponseBody
    public String first4(@PathVariable("id") String id) {
        System.out.println(id);
        return "我是一个好人4";
    }
}
